﻿using System;
using System.Windows.Markup;
using Garfield.Core;
using Garfield.Core.Runtime;

namespace Garfield.Presentation.Markup
{
    [MarkupExtensionReturnType(typeof(object))]
    public sealed class ServiceLocatorExtension : MarkupExtensionBase
    {
        private readonly Type api;

        public ServiceLocatorExtension(Type api)
        {
            this.api = api;
        }

        protected override object ProvideValue(IServiceProvider provider, IServiceLocator locator, IExtensionRegistry registry)
        {
            return registry.GetExtensions(Platform.Services).GetExtension(api);
        }
    }
}
